#include "Input.h"
#include "GlobalUse.h"
#include "BaseD3D.h"

VInput::VInput(void)
{
}

VInput::~VInput(void)
{
}

void VInput::InitInput()
{
	HWND hWnd = gfGetMainWin();

    m_rid[0].usUsage = 0x02;    // register mouse
    m_rid[0].usUsagePage = 0x01;    // top-level mouse
    m_rid[0].dwFlags = NULL;    // flags
    m_rid[0].hwndTarget = hWnd;    // handle to a window

    m_rid[1].usUsage = 0x06;    // register keyboard
    m_rid[1].usUsagePage = 0x01;    // top-level keyboard
    m_rid[1].dwFlags = NULL;    // flags
    m_rid[1].hwndTarget = hWnd;    // handle to a window

    RegisterRawInputDevices(m_rid, 2, sizeof(RAWINPUTDEVICE));    // register the device
}

void VInput::UpdateInputInfo(LPARAM lParam) 
{
	m_inputLast = m_inputData;

	UINT DataSize = sizeof(RAWINPUT);
	GetRawInputData((HRAWINPUT)lParam,
					RID_INPUT,
					&m_inputData,
					&DataSize,
					sizeof(RAWINPUTHEADER));

	VBaseD3D* baseD3D = gfGetD3DBase();
	baseD3D->CheckInput(m_inputData);
}

WORD VInput::GetPressedKey() {
	return m_inputData.data.keyboard.VKey;
}

bool VInput::IsKeyPressed(WORD wKeyName) {
	return (m_inputData.data.keyboard.VKey == wKeyName) && (m_inputLast.data.keyboard.VKey != wKeyName);
}

bool VInput::IsKeyHeld(WORD wKeyName) {
	return (m_inputData.data.keyboard.VKey == wKeyName) && (m_inputLast.data.keyboard.VKey == wKeyName);
}

float VInput::GetMouseX() {

	POINT MousePos;    // globally defined mouse position
	GetCursorPos(&MousePos);    // get the mouse data

	return (float)MousePos.x;
}

float VInput::GetMouseY() {
	POINT MousePos;    // globally defined mouse position
	GetCursorPos(&MousePos);    // get the mouse data

	return (float)MousePos.y;
}